brainhub-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +84 -0
- package/dist/adapters/claude.d.ts +2 -0
- package/dist/adapters/claude.js +50 -0
- package/dist/adapters/claude.js.map +1 -0
- package/dist/adapters/codex.d.ts +2 -0
- package/dist/adapters/codex.js +52 -0
- package/dist/adapters/codex.js.map +1 -0
- package/dist/adapters/content.d.ts +6 -0
- package/dist/adapters/content.js +68 -0
- package/dist/adapters/content.js.map +1 -0
- package/dist/adapters/grok.d.ts +2 -0
- package/dist/adapters/grok.js +44 -0
- package/dist/adapters/grok.js.map +1 -0
- package/dist/adapters/index.d.ts +31 -0
- package/dist/adapters/index.js +111 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/jsonl.d.ts +6 -0
- package/dist/adapters/jsonl.js +26 -0
- package/dist/adapters/jsonl.js.map +1 -0
- package/dist/adapters/types.d.ts +10 -0
- package/dist/adapters/types.js +2 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/auth/account-status.d.ts +50 -0
- package/dist/auth/account-status.js +59 -0
- package/dist/auth/account-status.js.map +1 -0
- package/dist/auth/google-account.d.ts +21 -0
- package/dist/auth/google-account.js +45 -0
- package/dist/auth/google-account.js.map +1 -0
- package/dist/auth/google-oauth.d.ts +35 -0
- package/dist/auth/google-oauth.js +191 -0
- package/dist/auth/google-oauth.js.map +1 -0
- package/dist/auth/oauth-loopback.d.ts +10 -0
- package/dist/auth/oauth-loopback.js +81 -0
- package/dist/auth/oauth-loopback.js.map +1 -0
- package/dist/auth/official-oauth-client.d.ts +5 -0
- package/dist/auth/official-oauth-client.js +6 -0
- package/dist/auth/official-oauth-client.js.map +1 -0
- package/dist/auth/platform-secrets.d.ts +14 -0
- package/dist/auth/platform-secrets.js +81 -0
- package/dist/auth/platform-secrets.js.map +1 -0
- package/dist/auth/secret-store-factory.d.ts +11 -0
- package/dist/auth/secret-store-factory.js +37 -0
- package/dist/auth/secret-store-factory.js.map +1 -0
- package/dist/auth/secret-store.d.ts +13 -0
- package/dist/auth/secret-store.js +40 -0
- package/dist/auth/secret-store.js.map +1 -0
- package/dist/capture/images.d.ts +11 -0
- package/dist/capture/images.js +27 -0
- package/dist/capture/images.js.map +1 -0
- package/dist/capture/normalize.d.ts +11 -0
- package/dist/capture/normalize.js +43 -0
- package/dist/capture/normalize.js.map +1 -0
- package/dist/capture/redact.d.ts +10 -0
- package/dist/capture/redact.js +60 -0
- package/dist/capture/redact.js.map +1 -0
- package/dist/cli/index.d.ts +20 -0
- package/dist/cli/index.js +781 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/clients/registry.d.ts +24 -0
- package/dist/clients/registry.js +105 -0
- package/dist/clients/registry.js.map +1 -0
- package/dist/domain/config-io.d.ts +15 -0
- package/dist/domain/config-io.js +168 -0
- package/dist/domain/config-io.js.map +1 -0
- package/dist/domain/config.d.ts +74 -0
- package/dist/domain/config.js +130 -0
- package/dist/domain/config.js.map +1 -0
- package/dist/domain/errors.d.ts +6 -0
- package/dist/domain/errors.js +11 -0
- package/dist/domain/errors.js.map +1 -0
- package/dist/domain/session.d.ts +62 -0
- package/dist/domain/session.js +47 -0
- package/dist/domain/session.js.map +1 -0
- package/dist/drive/drive-port.d.ts +51 -0
- package/dist/drive/drive-port.js +2 -0
- package/dist/drive/drive-port.js.map +1 -0
- package/dist/drive/google-drive.d.ts +28 -0
- package/dist/drive/google-drive.js +501 -0
- package/dist/drive/google-drive.js.map +1 -0
- package/dist/drive/memory-drive.d.ts +19 -0
- package/dist/drive/memory-drive.js +148 -0
- package/dist/drive/memory-drive.js.map +1 -0
- package/dist/drive/scoped-drive.d.ts +17 -0
- package/dist/drive/scoped-drive.js +115 -0
- package/dist/drive/scoped-drive.js.map +1 -0
- package/dist/mcp/server.d.ts +55 -0
- package/dist/mcp/server.js +133 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/portrait/obsidian.d.ts +7 -0
- package/dist/portrait/obsidian.js +16 -0
- package/dist/portrait/obsidian.js.map +1 -0
- package/dist/portrait/portrait-service.d.ts +12 -0
- package/dist/portrait/portrait-service.js +18 -0
- package/dist/portrait/portrait-service.js.map +1 -0
- package/dist/portrait/portrait-sync-service.d.ts +21 -0
- package/dist/portrait/portrait-sync-service.js +43 -0
- package/dist/portrait/portrait-sync-service.js.map +1 -0
- package/dist/runtime/command.d.ts +4 -0
- package/dist/runtime/command.js +2 -0
- package/dist/runtime/command.js.map +1 -0
- package/dist/runtime/container.d.ts +72 -0
- package/dist/runtime/container.js +361 -0
- package/dist/runtime/container.js.map +1 -0
- package/dist/scheduler/jobs.d.ts +2 -0
- package/dist/scheduler/jobs.js +7 -0
- package/dist/scheduler/jobs.js.map +1 -0
- package/dist/scheduler/launchd.d.ts +7 -0
- package/dist/scheduler/launchd.js +40 -0
- package/dist/scheduler/launchd.js.map +1 -0
- package/dist/scheduler/manager.d.ts +26 -0
- package/dist/scheduler/manager.js +113 -0
- package/dist/scheduler/manager.js.map +1 -0
- package/dist/search/chunk-text.d.ts +11 -0
- package/dist/search/chunk-text.js +40 -0
- package/dist/search/chunk-text.js.map +1 -0
- package/dist/search/e5-embedder.d.ts +19 -0
- package/dist/search/e5-embedder.js +71 -0
- package/dist/search/e5-embedder.js.map +1 -0
- package/dist/search/embedder.d.ts +8 -0
- package/dist/search/embedder.js +5 -0
- package/dist/search/embedder.js.map +1 -0
- package/dist/search/model-cache.d.ts +7 -0
- package/dist/search/model-cache.js +38 -0
- package/dist/search/model-cache.js.map +1 -0
- package/dist/search/search-service.d.ts +46 -0
- package/dist/search/search-service.js +319 -0
- package/dist/search/search-service.js.map +1 -0
- package/dist/setup/backfill-service.d.ts +33 -0
- package/dist/setup/backfill-service.js +47 -0
- package/dist/setup/backfill-service.js.map +1 -0
- package/dist/setup/setup-service.d.ts +65 -0
- package/dist/setup/setup-service.js +90 -0
- package/dist/setup/setup-service.js.map +1 -0
- package/dist/setup/uninstall-service.d.ts +34 -0
- package/dist/setup/uninstall-service.js +91 -0
- package/dist/setup/uninstall-service.js.map +1 -0
- package/dist/state/sqlite-store.d.ts +19 -0
- package/dist/state/sqlite-store.js +299 -0
- package/dist/state/sqlite-store.js.map +1 -0
- package/dist/state/store.d.ts +52 -0
- package/dist/state/store.js +2 -0
- package/dist/state/store.js.map +1 -0
- package/dist/status/status-service.d.ts +38 -0
- package/dist/status/status-service.js +93 -0
- package/dist/status/status-service.js.map +1 -0
- package/dist/update/update-check-service.d.ts +38 -0
- package/dist/update/update-check-service.js +105 -0
- package/dist/update/update-check-service.js.map +1 -0
- package/dist/upload/lock.d.ts +7 -0
- package/dist/upload/lock.js +68 -0
- package/dist/upload/lock.js.map +1 -0
- package/dist/upload/upload-service.d.ts +36 -0
- package/dist/upload/upload-service.js +360 -0
- package/dist/upload/upload-service.js.map +1 -0
- package/package.json +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# BrainHub MCP
|
|
2
|
+
|
|
3
|
+
BrainHub MCP 是一个仅在本机运行的 macOS MCP 服务。它读取 Claude Code、Codex CLI 和 Grok Build 的顶层会话,脱敏后上传到用户自己选择的 Google Drive,并提供本地语义搜索、完整会话读取和数字画像读取。
|
|
4
|
+
|
|
5
|
+
原始 CLI 会话始终只读。BrainHub MCP 不包含 cards、周报、云端处理、遥测或自更新器。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
第一版要求 macOS 与 Node.js `>=22.12.0`。
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g brainhub-mcp
|
|
13
|
+
brainhub-mcp setup
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`setup` 会依次完成:
|
|
17
|
+
|
|
18
|
+
1. 打开浏览器,让用户选择自己的 Google 账号并授权 Google Drive。
|
|
19
|
+
2. 创建或绑定该账号 My Drive 根目录下的 `brain-hub/`。若存在多个同名目录,流程会停止并要求用户明确选择。
|
|
20
|
+
3. 下载固定版本的 `Xenova/multilingual-e5-small`,并显示进度。
|
|
21
|
+
4. 统计本机可回填会话的数量与字节数;默认确认后上传历史会话。
|
|
22
|
+
5. 自动注册已安装的 MCP 客户端,并安装每日上传 launchd 任务。
|
|
23
|
+
6. 如显式指定 Obsidian vault,安装独立的每日画像覆盖任务。
|
|
24
|
+
|
|
25
|
+
流程可以重复运行。`setup` 会实时验证已有 Google 凭据与账号身份,并复用已完成的账号绑定、回填决定、客户端注册和 launchd 配置;未完成且仍有待重试项的回填会继续执行,不会再次询问。
|
|
26
|
+
|
|
27
|
+
## MCP 工具
|
|
28
|
+
|
|
29
|
+
- `upload_sessions`:上传新增或变化的 CLI 会话到 `brain-hub/inbox/<device>/`。
|
|
30
|
+
- `search_sessions`:刷新本地 inbox 索引并执行语义与关键词混合搜索。
|
|
31
|
+
- `get_session`:使用 `{source, conversation_id}` 返回 Drive 中的完整 inbox 会话。
|
|
32
|
+
- `get_portrait`:只读并完整返回 My Drive 根目录的 `Digital_Twin_Profile.md`。
|
|
33
|
+
- `hub_status`:返回账号、root、上传、模型、索引、launchd、画像、Obsidian 和 npm 版本状态。
|
|
34
|
+
|
|
35
|
+
`get_portrait` 不写 Obsidian。只有每日 `portrait sync` 任务会原子覆盖 `<vault>/BrainHub/portrait.md`;它不生成历史版本,也不读取周报。
|
|
36
|
+
|
|
37
|
+
## 账号与数据
|
|
38
|
+
|
|
39
|
+
一份配置只绑定一个当前 Google 账号,但可随时切换:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
brainhub-mcp auth switch
|
|
43
|
+
# 非交互接受新绑定的首次历史回填
|
|
44
|
+
brainhub-mcp auth switch --yes
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
每个“Google 账号 + 选定的 `brain-hub` root”绑定都有独立的上传水位、回填决定、重试状态和本地搜索索引。切换到首次使用的绑定时会执行与 `setup` 相同的历史回填确认;切回已完成的绑定时直接恢复原状态。refresh token 只进入 macOS Keychain,不写入 TOML、SQLite 或日志。
|
|
48
|
+
|
|
49
|
+
会话与图片只写入 `brain-hub/inbox/`。搜索的脱敏文本分块、向量、manifest 和 Drive change cursor 只保存在当前 Mac 的 SQLite 中,不写回 Drive。模型不可用时自动降级为关键词搜索,恢复后自动补齐缺失向量;Drive 刷新失败时保留旧 cursor 和最近有效索引并标记 stale。
|
|
50
|
+
|
|
51
|
+
## 升级与卸载
|
|
52
|
+
|
|
53
|
+
`hub_status` 最多每 24 小时查询一次 npm 最新版本。升级必须由用户主动执行:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install -g brainhub-mcp@latest
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
完整卸载:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
brainhub-mcp uninstall
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
卸载会移除 MCP 客户端注册、launchd、Google OAuth 授权、Keychain 凭据、配置、本地索引、状态和模型缓存。它不会删除或改写 Google Drive 与 Obsidian 中的任何内容。
|
|
66
|
+
|
|
67
|
+
## 源码开发
|
|
68
|
+
|
|
69
|
+
官方 npm 包在发布时注入 BrainHub 的 Desktop OAuth 配置。源码构建与 fork 必须使用自己的 Google Cloud Desktop OAuth Client,不得提交 client secret 或 refresh token。
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pnpm install --frozen-lockfile
|
|
73
|
+
pnpm test
|
|
74
|
+
pnpm typecheck
|
|
75
|
+
pnpm lint
|
|
76
|
+
pnpm format:check
|
|
77
|
+
pnpm build
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
详细配置与源码 OAuth 方法见 [docs/configuration.md](docs/configuration.md),数据使用与删除说明见 [docs/privacy.md](docs/privacy.md)。
|
|
81
|
+
|
|
82
|
+
## 许可
|
|
83
|
+
|
|
84
|
+
Apache License 2.0。安全问题请使用 GitHub Security Advisory 私下报告。
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { stat } from "node:fs/promises";
|
|
2
|
+
import { NormalizedSessionSchema } from "../domain/session.js";
|
|
3
|
+
import { visibleTurnContent, timestampBounds } from "./content.js";
|
|
4
|
+
import { asRecord, asString, readJsonLines } from "./jsonl.js";
|
|
5
|
+
export async function parseClaudeSession(path, options) {
|
|
6
|
+
const [{ records, malformedLines }, fileStat] = await Promise.all([
|
|
7
|
+
readJsonLines(path),
|
|
8
|
+
stat(path),
|
|
9
|
+
]);
|
|
10
|
+
const objects = records.map(asRecord).filter((value) => value !== null);
|
|
11
|
+
const isSidechain = objects.some((record) => record.isSidechain === true);
|
|
12
|
+
if (isSidechain && !options.includeSubagents) {
|
|
13
|
+
return { session: null, skippedSubagent: true, malformedLines };
|
|
14
|
+
}
|
|
15
|
+
const turns = [];
|
|
16
|
+
const timestamps = [];
|
|
17
|
+
let conversationId = null;
|
|
18
|
+
for (const record of objects) {
|
|
19
|
+
conversationId ??= asString(record.sessionId);
|
|
20
|
+
timestamps.push(asString(record.timestamp));
|
|
21
|
+
if (record.type !== "user" && record.type !== "assistant")
|
|
22
|
+
continue;
|
|
23
|
+
const message = asRecord(record.message);
|
|
24
|
+
if (!message)
|
|
25
|
+
continue;
|
|
26
|
+
const role = message?.role;
|
|
27
|
+
if (role !== "user" && role !== "assistant")
|
|
28
|
+
continue;
|
|
29
|
+
const turn = visibleTurnContent(role, message.content);
|
|
30
|
+
if (turn)
|
|
31
|
+
turns.push(turn);
|
|
32
|
+
}
|
|
33
|
+
if (!conversationId || turns.length === 0) {
|
|
34
|
+
return { session: null, skippedSubagent: false, malformedLines };
|
|
35
|
+
}
|
|
36
|
+
const bounds = timestampBounds(timestamps, fileStat.mtime.toISOString());
|
|
37
|
+
const session = NormalizedSessionSchema.parse({
|
|
38
|
+
source: "claude-code",
|
|
39
|
+
conversationId,
|
|
40
|
+
device: options.device,
|
|
41
|
+
...bounds,
|
|
42
|
+
turns,
|
|
43
|
+
sourcePath: path,
|
|
44
|
+
warnings: malformedLines > 0
|
|
45
|
+
? [`Ignored ${malformedLines} malformed JSONL line(s)`]
|
|
46
|
+
: [],
|
|
47
|
+
});
|
|
48
|
+
return { session, skippedSubagent: false, malformedLines };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=claude.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/adapters/claude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,OAAO,EAAE,uBAAuB,EAAa,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG/D,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAY,EACZ,OAAuB;IAEvB,MAAM,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAChE,aAAa,CAAC,IAAI,CAAC;QACnB,IAAI,CAAC,IAAI,CAAC;KACX,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC;IACxE,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,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K,CAAC,WAAW,EAAE,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,uBAAuB,CAAC,KAAK,CAAC;QAC5C,MAAM,EAAE,aAAa;QACrB,cAAc;QACd,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,MAAM;QACT,KAAK;QACL,UAAU,EAAE,IAAI;QAChB,QAAQ,EACN,cAAc,GAAG,CAAC;YAChB,CAAC,CAAC,CAAC,WAAW,cAAc,0BAA0B,CAAC;YACvD,CAAC,CAAC,EAAE;KACT,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
3
|
+
import { NormalizedSessionSchema } from "../domain/session.js";
|
|
4
|
+
import { visibleTurnContent, timestampBounds } from "./content.js";
|
|
5
|
+
import { asRecord, asString, readJsonLines } from "./jsonl.js";
|
|
6
|
+
export async function parseCodexSession(path, options) {
|
|
7
|
+
const [{ records, malformedLines }, fileStat] = await Promise.all([
|
|
8
|
+
readJsonLines(path),
|
|
9
|
+
stat(path),
|
|
10
|
+
]);
|
|
11
|
+
const objects = records.map(asRecord).filter((value) => value !== null);
|
|
12
|
+
const metadata = objects.find((record) => record.type === "session_meta");
|
|
13
|
+
const metaPayload = asRecord(metadata?.payload);
|
|
14
|
+
const isSubagent = asRecord(metaPayload?.source)?.subagent !== undefined;
|
|
15
|
+
if (isSubagent && !options.includeSubagents) {
|
|
16
|
+
return { session: null, skippedSubagent: true, malformedLines };
|
|
17
|
+
}
|
|
18
|
+
const turns = [];
|
|
19
|
+
const timestamps = [];
|
|
20
|
+
for (const record of objects) {
|
|
21
|
+
timestamps.push(asString(record.timestamp));
|
|
22
|
+
if (record.type !== "response_item")
|
|
23
|
+
continue;
|
|
24
|
+
const payload = asRecord(record.payload);
|
|
25
|
+
if (payload?.type !== "message")
|
|
26
|
+
continue;
|
|
27
|
+
const role = payload.role;
|
|
28
|
+
if (role !== "user" && role !== "assistant")
|
|
29
|
+
continue;
|
|
30
|
+
const turn = visibleTurnContent(role, payload.content);
|
|
31
|
+
if (turn)
|
|
32
|
+
turns.push(turn);
|
|
33
|
+
}
|
|
34
|
+
const conversationId = asString(metaPayload?.id) ?? basename(path, ".jsonl");
|
|
35
|
+
if (turns.length === 0) {
|
|
36
|
+
return { session: null, skippedSubagent: false, malformedLines };
|
|
37
|
+
}
|
|
38
|
+
const bounds = timestampBounds([asString(metaPayload?.timestamp), ...timestamps], fileStat.mtime.toISOString());
|
|
39
|
+
const session = NormalizedSessionSchema.parse({
|
|
40
|
+
source: "codex",
|
|
41
|
+
conversationId,
|
|
42
|
+
device: options.device,
|
|
43
|
+
...bounds,
|
|
44
|
+
turns,
|
|
45
|
+
sourcePath: path,
|
|
46
|
+
warnings: malformedLines > 0
|
|
47
|
+
? [`Ignored ${malformedLines} malformed JSONL line(s)`]
|
|
48
|
+
: [],
|
|
49
|
+
});
|
|
50
|
+
return { session, skippedSubagent: false, malformedLines };
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=codex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex.js","sourceRoot":"","sources":["../../src/adapters/codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,OAAO,EAAE,uBAAuB,EAAa,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG/D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAY,EACZ,OAAuB;IAEvB,MAAM,CAAC,EAAE,OAAO,EAA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MAAM,IAAI,GAAG,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QACvD,IAAI,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,MAAM,cAAc,GAAG,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC7E,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC;IACnE,CAAC;IACD,MAAM,MAAM,GAAG,eAAe,CAC5B,CAAC,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC,EAAE,GAAG,UAAU,CAAC,EACjD,QAAQ,CAAC,KAAK,CAAC,WAAW,EAAE,CAC7B,CAAC;IACF,MAAM,OAAO,GAAG,uBAAuB,CAAC,KAAK,CAAC;QAC5C,MAAM,EAAE,OAAO;QACf,cAAc;QACd,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,MAAM;QACT,KAAK;QACL,UAAU,EAAE,IAAI;QAChB,QAAQ,EACN,cAAc,GAAG,CAAC;YAChB,CAAC,CAAC,CAAC,WAAW,cAAc,0BAA0B,CAAC;YACvD,CAAC,CAAC,EAAE;KACT,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Turn } from "../domain/session.js";
|
|
2
|
+
export declare function visibleTurnContent(role: "user" | "assistant", content: unknown): Turn | null;
|
|
3
|
+
export declare function timestampBounds(values: Array<string | null>, fallback: string): {
|
|
4
|
+
startedAt: string;
|
|
5
|
+
updatedAt: string;
|
|
6
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { asRecord, asString } from "./jsonl.js";
|
|
2
|
+
const visibleTextTypes = new Set(["text", "input_text", "output_text"]);
|
|
3
|
+
function parseImage(part) {
|
|
4
|
+
const source = asRecord(part.source);
|
|
5
|
+
if (source?.type === "base64") {
|
|
6
|
+
const data = asString(source.data);
|
|
7
|
+
const mediaType = asString(source.media_type) ?? asString(source.mediaType);
|
|
8
|
+
return data && mediaType ? { kind: "embedded", mediaType, data } : null;
|
|
9
|
+
}
|
|
10
|
+
const url = asString(part.image_url) ??
|
|
11
|
+
asString(part.url) ??
|
|
12
|
+
(asRecord(part.image_url) ? asString(asRecord(part.image_url)?.url) : null);
|
|
13
|
+
if (!url)
|
|
14
|
+
return null;
|
|
15
|
+
if (url.startsWith("data:")) {
|
|
16
|
+
const match = /^data:([^;,]+);base64,(.+)$/u.exec(url);
|
|
17
|
+
return match?.[1] && match[2]
|
|
18
|
+
? { kind: "embedded", mediaType: match[1], data: match[2] }
|
|
19
|
+
: null;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
new URL(url);
|
|
23
|
+
return { kind: "remote", url };
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function visibleTurnContent(role, content) {
|
|
30
|
+
if (typeof content === "string") {
|
|
31
|
+
return content.length > 0 ? { role, text: content, images: [] } : null;
|
|
32
|
+
}
|
|
33
|
+
if (!Array.isArray(content))
|
|
34
|
+
return null;
|
|
35
|
+
const texts = [];
|
|
36
|
+
const images = [];
|
|
37
|
+
for (const value of content) {
|
|
38
|
+
const part = asRecord(value);
|
|
39
|
+
if (!part)
|
|
40
|
+
continue;
|
|
41
|
+
const type = asString(part.type);
|
|
42
|
+
if (type && visibleTextTypes.has(type)) {
|
|
43
|
+
const text = asString(part.text);
|
|
44
|
+
if (text)
|
|
45
|
+
texts.push(text);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (type === "image" || type === "input_image" || part.image_url) {
|
|
49
|
+
const image = parseImage(part);
|
|
50
|
+
if (image)
|
|
51
|
+
images.push(image);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const text = texts.join("\n");
|
|
55
|
+
return text || images.length > 0 ? { role, text, images } : null;
|
|
56
|
+
}
|
|
57
|
+
export function timestampBounds(values, fallback) {
|
|
58
|
+
const valid = values
|
|
59
|
+
.filter((value) => Boolean(value))
|
|
60
|
+
.map((value) => new Date(value))
|
|
61
|
+
.filter((value) => !Number.isNaN(value.valueOf()))
|
|
62
|
+
.sort((left, right) => left.valueOf() - right.valueOf());
|
|
63
|
+
return {
|
|
64
|
+
startedAt: (valid.at(0) ?? new Date(fallback)).toISOString(),
|
|
65
|
+
updatedAt: (valid.at(-1) ?? new Date(fallback)).toISOString(),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../src/adapters/content.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC;AAExE,SAAS,UAAU,CAAC,IAA6B;IAC/C,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,MAAM,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC5E,OAAO,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,I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,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;SAC/B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;SACjD,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3D,OAAO;QACL,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE;QAC5D,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE;KAC9D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { basename, join } from "node:path";
|
|
2
|
+
import { readFile, stat } from "node:fs/promises";
|
|
3
|
+
import { NormalizedSessionSchema } from "../domain/session.js";
|
|
4
|
+
import { timestampBounds, visibleTurnContent } from "./content.js";
|
|
5
|
+
import { asRecord, asString, readJsonLines } from "./jsonl.js";
|
|
6
|
+
export async function parseGrokSession(directory, options) {
|
|
7
|
+
const historyPath = join(directory, "chat_history.jsonl");
|
|
8
|
+
const [{ records, malformedLines }, summaryText, fileStat] = await Promise.all([
|
|
9
|
+
readJsonLines(historyPath),
|
|
10
|
+
readFile(join(directory, "summary.json"), "utf8"),
|
|
11
|
+
stat(historyPath),
|
|
12
|
+
]);
|
|
13
|
+
const summary = asRecord(JSON.parse(summaryText));
|
|
14
|
+
const isSubagent = summary?.session_kind === "subagent";
|
|
15
|
+
if (isSubagent && !options.includeSubagents) {
|
|
16
|
+
return { session: null, skippedSubagent: true, malformedLines };
|
|
17
|
+
}
|
|
18
|
+
const turns = [];
|
|
19
|
+
for (const value of records) {
|
|
20
|
+
const record = asRecord(value);
|
|
21
|
+
if (!record || (record.type !== "user" && record.type !== "assistant"))
|
|
22
|
+
continue;
|
|
23
|
+
const turn = visibleTurnContent(record.type, record.content);
|
|
24
|
+
if (turn)
|
|
25
|
+
turns.push(turn);
|
|
26
|
+
}
|
|
27
|
+
if (turns.length === 0) {
|
|
28
|
+
return { session: null, skippedSubagent: false, malformedLines };
|
|
29
|
+
}
|
|
30
|
+
const bounds = timestampBounds([asString(summary?.created_at), asString(summary?.updated_at)], fileStat.mtime.toISOString());
|
|
31
|
+
const session = NormalizedSessionSchema.parse({
|
|
32
|
+
source: "grok-build",
|
|
33
|
+
conversationId: basename(directory),
|
|
34
|
+
device: options.device,
|
|
35
|
+
...bounds,
|
|
36
|
+
turns,
|
|
37
|
+
sourcePath: directory,
|
|
38
|
+
warnings: malformedLines > 0
|
|
39
|
+
? [`Ignored ${malformedLines} malformed JSONL line(s)`]
|
|
40
|
+
: [],
|
|
41
|
+
});
|
|
42
|
+
return { session, skippedSubagent: false, malformedLines };
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=grok.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok.js","sourceRoot":"","sources":["../../src/adapters/grok.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,uBAAuB,EAAa,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG/D,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,SAAiB,EACjB,OAAuB;IAEvB,MAAM,WAAW,GAAG,IAAI,CAAC,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QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,EAC9D,QAAQ,CAAC,KAAK,CAAC,WAAW,EAAE,CAC7B,CAAC;IACF,MAAM,OAAO,GAAG,uBAAuB,CAAC,KAAK,CAAC;QAC5C,MAAM,EAAE,YAAY;QACpB,cAAc,EAAE,QAAQ,CAAC,SAAS,CAAC;QACnC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,MAAM;QACT,KAAK;QACL,UAAU,EAAE,SAAS;QACrB,QAAQ,EACN,cAAc,GAAG,CAAC;YAChB,CAAC,CAAC,CAAC,WAAW,cAAc,0BAA0B,CAAC;YACvD,CAAC,CAAC,EAAE;KACT,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { NormalizedSession, SessionSource } from "../domain/session.js";
|
|
2
|
+
export interface DiscoveryOptions {
|
|
3
|
+
device: string;
|
|
4
|
+
includeSubagents: boolean;
|
|
5
|
+
sources: SessionSource[];
|
|
6
|
+
paths: {
|
|
7
|
+
claude: string[];
|
|
8
|
+
codex: string[];
|
|
9
|
+
grok: string[];
|
|
10
|
+
};
|
|
11
|
+
modifiedAfter?: Partial<Record<SessionSource, string>>;
|
|
12
|
+
includePaths?: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface DiscoveryStatus {
|
|
15
|
+
discovered: number;
|
|
16
|
+
captured: number;
|
|
17
|
+
skippedSubagents: number;
|
|
18
|
+
malformed: number;
|
|
19
|
+
errors: number;
|
|
20
|
+
}
|
|
21
|
+
export interface DiscoveryResult {
|
|
22
|
+
sessions: NormalizedSession[];
|
|
23
|
+
skippedSubagents: number;
|
|
24
|
+
malformed: number;
|
|
25
|
+
warnings: Array<{
|
|
26
|
+
code: string;
|
|
27
|
+
message: string;
|
|
28
|
+
}>;
|
|
29
|
+
status: Record<"claude" | "codex" | "grok", DiscoveryStatus>;
|
|
30
|
+
}
|
|
31
|
+
export declare function discoverSessions(options: DiscoveryOptions): Promise<DiscoveryResult>;
|